using UnityEngine;
using System.Collections;

/// <summary>
/// Linea recta. Hereda las propiedades de la Linea. Esta clase se encarga de dibujar rectas.
/// </summary>
public class LineaRecta : Linea {
	
	float m;
	float b;
	float xdif;
	
	/// <summary>
	/// Awake this instance.
	/// </summary>
	void Awake () {
	
		m = (destino.position.y - inicio.position.y)/(destino.position.x - inicio.position.x);
		b = destino.position.y - m*(destino.position.x);
		xdif = destino.position.x - inicio.position.x;
		length= Length();
	}
	
	/// <summary>
	/// Raises the draw gizmos event. Dibuja la linea recta
	/// </summary>
	void OnDrawGizmos()
	{
		Gizmos.color=Color.red;
		if (drawLines)
		{
			
			Gizmos.DrawLine(inicio.transform.position, destino.transform.position);
		}
	}
	
	/// <summary>
	/// Calculates the point.
	/// </summary>
	/// <returns>
	/// The point.
	/// </returns>
	/// <param name='t'>
	/// T.
	/// </param>
	public override  Vector3 CalculatePoint(float t)
	{
		float actualXpos= t*xdif;
		float mx = m*(actualXpos + inicio.position.x);
		float y  = mx + b;
		
		return new Vector3(actualXpos + inicio.position.x, y,0);
	}
	
	/// <summary>
	/// Longitud de la recta
	/// </summary>
	public override float Length ()
	{
		
		return longitudPitagoras(inicio.position, destino.position);
	}
}
